﻿package commands 
{
	import flash.utils.ByteArray;
	import commands.classesinfo.*;
	
	/**
	 * ...
	 * @author wwx
	 * 10000000 创建角色
	 */
	public class CreateRoleCmdReq extends abCommand
	{
		
		public function CreateRoleCmdReq() //: abCommand(CommandType.CMD_TYPE_CREATEROLE_REQ)
		{
			super(CommandType(CommandType.CMD_TYPE_CREATEROLE_REQ));
			msgSeq = 10000000;
		}
		
		private var msgSeq:int;//消息号
		public var reserve:int;//保留字段
		
		public var accountNum:String;//帐号,不超过100字节
		public var passWord:String;//密码,不超过25字节
		public var sex:int;//性别,1：男 2:女
		
		public function convertToBytes(bytes:ByteArray, offset:int):int
		{
/*			
			var len:int = 0;
			len += offset;
			bytes.position = offset;
			
			bytes.writeInt(msgSeq);
			len += 4;
			bytes.writeInt(reserve);
			len += 4;

			bytes.writeShort(accountNum.length);
			len += 2;
			bytes.writeMultiByte(accountNum, "gb2312");
			len += accountNum.length;
			bytes.writeShort(passWord.length);
			len += 2;
			bytes.writeMultiByte(passWord, "gb2312");
			len += passWord.length;
			bytes.writeInt(sex);				
			len += 4;
*/			
			var len:int = 0;
			len += offset;
			bytes.position = offset;
			
			//bytes.writeInt(msgSeq);
			bytes[offset + 0] = (msgSeq & 0xff);
			bytes[offset + 1] = ((msgSeq >> 8) & 0xff);
			bytes[offset + 2] = ((msgSeq >> 16) & 0xff);
			bytes[offset + 3] = ((msgSeq >> 24) & 0xff);			
			len += 4;
			offset += 4;
			bytes.position = offset;
			//bytes.writeInt(reserve);
			bytes[offset + 0] = (reserve & 0xff);
			bytes[offset + 1] = ((reserve >> 8) & 0xff);
			bytes[offset + 2] = ((reserve >> 16) & 0xff);
			bytes[offset + 3] = ((reserve >> 24) & 0xff);				
			len += 4;
			offset += 4;
			bytes.position = offset;

			//bytes.writeShort(accountNum.length);
			bytes[offset + 0] = (accountNum.length & 0xff);
			bytes[offset + 1] = ((accountNum.length >> 8) & 0xff);			
			len += 2;
			offset += 2;
			bytes.position = offset;			
			bytes.writeMultiByte(accountNum, "gb2312");
			len += accountNum.length;
			offset += accountNum.length;
			bytes.position = offset;
			
			//bytes.writeShort(passWord.length);
			bytes[offset + 0] = (passWord.length & 0xff);
			bytes[offset + 1] = ((passWord.length >> 8) & 0xff);				
			len += 2;
			offset += 2;
			bytes.position = offset;			
			bytes.writeMultiByte(passWord, "gb2312");
			len += passWord.length;
			offset += passWord.length;
			bytes.position = offset;
						
			//bytes.writeInt(sex);
			bytes[offset + 0] = (sex & 0xff);
			bytes[offset + 1] = ((sex >> 8) & 0xff);
			bytes[offset + 2] = ((sex >> 16) & 0xff);
			bytes[offset + 3] = ((sex >> 24) & 0xff);				
			len += 4;		
			offset += 4;
			bytes.position = offset;	
			bytes.length = offset;
			return len;
		}
	}
	
}